package main

import "fmt"

func searchRange(nums []int, target int) []int {
	if len(nums) == 0 {
		return []int{-1, -1}
	}
	left := 0
	right := len(nums) - 1
	middle := -1
	for left <= right {
		middle = left + (right-left)/2
		if nums[middle] < target {
			left = middle + 1
		} else if nums[middle] > target {
			right = middle - 1
		} else {
			break
		}
	}
	if nums[middle] != target {
		return []int{-1, -1}
	}
	// 判断左右边界
	left = middle
	right = middle
	for ; left >= 0 && nums[left] == target; left-- {

	}
	for ; right <= (len(nums)-1) && nums[right] == target; right++ {

	}
	return []int{left + 1, right - 1}

}
func main() {
	nums := []int{1}
	fmt.Println(searchRange(nums, 1))
}
